package com.jzqf.harmonydemo.utils;

import ohos.aafwk.ability.SystemMemoryInfo;
import ohos.account.AccountAbility;
import ohos.app.Context;
import ohos.app.IAbilityManager;

/**
 * 手机工具类
 *
 * @author LiuWeiHao
 * 2021/5/19 17:40
 */
public class MobileUtil {
    /**
     * 获取RAM总内存
     *
     * @param context 上下文
     * @return 单位:M
     */
    public static long totalMemory(Context context) {
        SystemMemoryInfo systemMemoryInfo = new SystemMemoryInfo();
        IAbilityManager abilityManager = context.getAbilityManager();
        abilityManager.getSystemMemoryInfo(systemMemoryInfo);
        return systemMemoryInfo.getTotalSysMem() >> 20;
    }

    /**
     * 获取RAM可用内存
     *
     * @param context 上下文
     * @return 单位:M
     */
    public static long availMemory(Context context) {
        SystemMemoryInfo systemMemoryInfo = new SystemMemoryInfo();
        IAbilityManager abilityManager = context.getAbilityManager();
        abilityManager.getSystemMemoryInfo(systemMemoryInfo);
        return systemMemoryInfo.getAvailSysMem() >> 20;
    }

    //TODO 虚拟ID拿到的是空
    public static String getDVID() {
        return AccountAbility.getAccountAbility().getDistributedVirtualDeviceId();
    }
}
